/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 周斌
 * Date: 2024-01-22
 * Time: 14:56
 */
public class Test {
    public static int removeElement(int[] nums,int val) {
        int ret = nums.length;//ret为数组的长度
        //遍历数组nums
        for(int i = 0; i<ret;) {
            //如果相同则将数组最后一位与num[i]交换，并且ret减1
            if(nums[i] == val) {
                nums[i] = nums[ret-1];
                ret--;
            } else {
                //如果不相同i+1
                i++;
            }
        }
        return ret;
    }
    public static void main(String[] args) {
        int[] nums = {3,2,2,3};
        int ret = removeElement(nums,3);
        System.out.println(ret);
    }
}
